import React from 'react';
import { connect } from 'dva';
import { routerRedux } from 'dva/router';
import { List, Icon,TextareaItem } from 'antd-mobile';
import content from '../../../common/contentCss/content.css';
import CustTitle from '../../../common/title/title';
import BasicInfo from './pages/basicInfo/basicInfo';
import Intention from './pages/intention/intention';
import MyAppraise from './pages/myAppraise/myAppraise';
import WorkExperience from './pages/workExperience/workExperience';
import MyEducation from './pages/myEducation/myEducation';


function MyResume({dispatch,loading,myResume,personal}) {
  const { intentionData } = myResume
  const { profile,resume,personalData,resumeModel } = personal;

  // console.log('personalData',JSON.stringify(personalData));

  const titleProps = {
    titleName:'我的简历',
    showSaveBtnStatus: true,
    saveBtnName: '',//
    goBack(){
      history.go(-1);
    },
    onSave(){
      console.log('我的简历----保存')
    },
  }

  const BasicInfoProps = {
    profile,
    gpsDistance:personalData.gpsDistance,
    onOk(){
      console.log('编辑');
      dispatch(routerRedux.push({
        pathname: '/simple-info',
      }));
    }
  }

  const IntentionProps = {
    intentionData,
    onOk(){
      console.log('求职意向---编辑');
      dispatch(routerRedux.push({
        pathname: '/job-intention',
      }));
    }
  }

  const MyAppraiseProps = {
    resume,
    onAdd(){
      console.log('添加个人评价');
      dispatch(routerRedux.push({
        pathname: '/add-appraise',
      }));
    },
    onOk(){
      console.log('编辑');
      dispatch(routerRedux.push({
        pathname: '/add-appraise',
      }));
    }
  }

  const WorkExperienceProps = {
    resumeModel,
    textName: '工作经历',
    onAdd(){
      console.log('添加个人经历');
      dispatch(routerRedux.push({
        pathname: '/set-work-experience',
      }));
    },
    onOk(){
      console.log('添加工作经历');
      dispatch({
        type: 'setWorkExperience/querySuccess',
        payload:{
          pageStatus:'add',
          entryTime:'',
          dimissionTime: '',
          workCompany:'',
          workPost:'',
          description:'',
        }
      });
      dispatch(routerRedux.push({
        pathname: '/set-work-experience',
      }));
    },
    onViewDetail(item){
      const { entryTime, dimissionTime, workCompany, workPost, description} = item;
      dispatch({
        type: 'setWorkExperience/querySuccess',
        payload:{
          pageStatus:'edit',
          id:item.id,
          entryTime,
          dimissionTime,
          workCompany,
          workPost,
          description,
        }
      });
      dispatch(routerRedux.push({
        pathname: '/set-work-experience',
      }));
    }
  }

  const MyEducationProps = {
    resumeModel,
    textName: '教育经历',
    onAdd(){
      // console.log('添加教育背景');
      dispatch(routerRedux.push({
        pathname: '/set-education',
      }));
    },
    onOk(){
      // console.log('进入列表');
      dispatch({
        type: 'setEducation/querySuccess',
        payload:{
          pageStatus:'add',
          entranceTime:'',
          graduationTime:'',
          collegeName:'',
          education:'',
          major:'',
          description:'',
        },
      });
      dispatch(routerRedux.push({
        pathname: '/set-education',
      }));
    },
    onViewDetail(item){
      const { entranceTime, graduationTime, collegeName,
       education, major, description } = item;
      dispatch({
        type: 'setEducation/querySuccess',
        payload:{
          pageStatus:'edit',
          id:item.id,
          entranceTime,
          graduationTime,
          collegeName,
          education,
          major,
          description,
        }
      });
      dispatch(routerRedux.push({
        pathname: '/set-education',
      }));
    }
  }

  const MarginHeight = () => <div style={{height: '0.1em', backgroundColor:'#F5F5F9'}}></div>;

  return(
    <div className={content.content}>
      <CustTitle {...titleProps}/>
      <div style={{
        marginTop: '2.8125em',
      }}>
      </div>
      <BasicInfo {...BasicInfoProps} />
      <MarginHeight />
      <Intention {...IntentionProps} />
      <MarginHeight />
      <MyAppraise {...MyAppraiseProps}/>
      <MarginHeight />
      <WorkExperience {...WorkExperienceProps}/>
      <MarginHeight />
      <MyEducation {...MyEducationProps} />
      <MarginHeight />

    </div>
  )
}

function mapStateToProps(state, ownProps) {
  return {
    myResume: state.myResume,
    personal: state.personal
  }
}

export default connect(mapStateToProps)(MyResume);
